package com.mycontract.suitepro.contract

import com.mycontract.suitepro.data.RevObjContractOrder

object ContractSignManager {

    // 手机号前缀
    var mPhonePreHint: String = ""

    // 订单列表
    val mOrderList = mutableListOf<RevObjContractOrder>()

    // 订单号
    var mOrderId: String = ""

    // token
    var mToken: String = ""

    // 产品
    var mProduct: String = ""

    // 手机号
    var mMobile: String = ""

    // 来源
    var mSourceType: String = ""

    // scheme 只有是mSourceType=app时才有值
    var mScheme: String = ""

    // host mSourceType=h5时，它为来源地址
    var mHost: String = ""

    // 是否需要刷新页面
    var mNeedReladData:Boolean = false

    /** 从 app 回传初始化 */
    fun initFormAppParams() {
        mOrderId = ContractParamsFromApp.mOrderId
        mProduct = ContractParamsFromApp.mProduct
        mMobile = ContractParamsFromApp.mMobile
        mSourceType = ContractParamsFromApp.mSourceType
        mScheme = ContractParamsFromApp.mScheme
        mHost = ContractParamsFromApp.mHost
    }

    /** 从 referrer 回传初始化 */
    fun initFormReferrerParams() {
        mOrderId = ContractParamsFromReferrer.mOrderId
        mProduct = ContractParamsFromReferrer.mProduct
        mMobile = ContractParamsFromReferrer.mMobile
        mSourceType = ContractParamsFromReferrer.mSourceType
        mScheme = ContractParamsFromReferrer.mScheme
        mHost = ContractParamsFromReferrer.mHost
    }

    /** 从 clipboard 回传初始化 */
    fun initFormClipboardParams() {
        mOrderId = ContractParamsFromClipboard.mClipboardText
//        mProduct = ContractParamsFromClipboard.mProduct
//        mMobile = ContractParamsFromClipboard.mMobile
//        mSourceType = ContractParamsFromClipboard.mSourceType
//        mScheme = ContractParamsFromClipboard.mScheme
//        mHost = ContractParamsFromClipboard.mHost
    }

    /** 将产品格式化 [xxxx] */
    fun formatProduct(): String {
        if (mProduct.contains(",", true)) {
            var result = ""
            val products = mProduct.split(",")
            for (index in 0 until products.size) {
                val item = products[index]
                if (item.isNotBlank()) {
                    if (result.isNotBlank()) {
                        result = "${result},[${item}]"
                    } else {
                        result = "[${item}]"
                    }
                }
            }
            return result
        }
        return "[$mProduct]"
    }
}